<?php
header("Content-type: text/html; charset=utf-8");
require_once("config.php");
require_once 'wappay/service/AlipayTradeService.php';

function kgLog($msg){
		$filename = date('Y-m-d')."log.txt";
		$file = fopen($filename,'a');
		$msg = '['.date('Y-m-d H:i:s').'] '.$msg."\r\n";
		fwrite($file, $msg, 4096);
		fclose($file);
	}

$arr=$_GET;
$alipaySevice = new AlipayTradeService($config); 
$result = $alipaySevice->check($arr);
$out_trade_no = htmlspecialchars($_GET['out_trade_no']);
$trade_no = htmlspecialchars($_GET['trade_no']);	
if($result) {//验证成功
	
    kgLog("out_trade_no:".$out_trade_no."return ok");
	//支付宝交易号
	
    kgLog("trade_no:".$trade_no."return ok");
	//echo "验证成功<br />外部订单号：".$out_trade_no;
        echo '<html>
    <head>
           <meta http-equiv="content-type" content="text/html;charset=utf-8"/>

    <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <title>支付成功</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div onclick="Call()" style="background: #66CD00; border-bottom: 1px solid #66CD00;padding: 10px;margin: 10px;text-align: center;color: #fff;">支付成功</div>
    </body>
</html>
';
}
else {
       kgLog("out_trade_no:".$out_trade_no."return fail");
    kgLog("trade_no:".$trade_no."return fail");
     echo '<html>
    <head>
           <meta http-equiv="content-type" content="text/html;charset=utf-8"/>

    <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <title>支付失败</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div onclick="Call()" style="background: #66CD00; border-bottom: 1px solid #66CD00;padding: 10px;margin: 10px;text-align: center;color: #fff;">支付失败</div>
    </body>
</html>
';
    
}
?>
